package sma.agent;

import model.ApplicationModel;
import sma.behaviour.MTStatechartDiscoveryBehaviour;
import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

public class MTStatechartAgent extends Agent {

	private static final long serialVersionUID = -2287194284286518753L;

	private ApplicationModel applicationModel;

	public MTStatechartAgent() {
	}

	@Override
	public void setup() {
		this.applicationModel = (ApplicationModel) getArguments()[0];
		registerService();
		
		addBehaviour(new MTStatechartDiscoveryBehaviour(applicationModel.getProjects()));
	}

	private void registerService() {
		DFAgentDescription dfd = new DFAgentDescription();
		dfd.setName(getAID());
		ServiceDescription sd = new ServiceDescription();
		sd.setType("mtStatechart");
		sd.setName("mtStatechartAgent");
		dfd.addServices(sd);
		try {
			DFService.register(this, dfd);
		} catch (FIPAException fe) {
			fe.printStackTrace();
		}
	}
}
